<template>
  <div class="search">
    <div class="welcome">
      <p>欢迎您，请填写送餐地址:</p>
    </div>
    <div class="address">
      <p class="add-test">送餐城市:</p>
      <input class="search-input" type="text" placeholder="请输入城市" v-model="inputCity">
    </div>
    <div class="man">
      <p class="man-test">联系人:</p>
      <input class="man-input" type="text" placeholder="请输入联系人" v-model="inputMan">
      <form class="sex">
        <input type="radio" name="people" value="man" checked="checked1" @click="checkedNan()">先生
        <input type="radio" name="people" value="woman" @click="checkedNan2()">女士
      </form>
    </div>
    <div class="num">
      <p class="num-test">联系电话:</p>
      <input class="num-input" type="text" placeholder="请输入联系电话" v-model="inputPhone">
      <button class="save" @click="handleClick()">保存</button>
    </div>
    <div class="tips">
      <p class="tips-test">如此处与路名/小区名填写内容有矛盾，视为无效订单</p>
      <p class="tips-test">此处仅支持中文输入地址。</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CitySearch',
  data: function () {
    return {
      inputCity: '',
      inputMan: '',
      inputPhone: '',
      checked1: true,
      who: '先生'
    }
  },
  methods: {
    handleClick () {
      let iC = this.inputCity.replace(/\s*/g, '')
      let iM = this.inputMan.replace(/\s*/g, '')
      let iP = this.inputPhone.replace(/\s*/g, '')
      if (iC.length !== 0 && iM.length !== 0 && iP.length !== 0) {
      } else {
        alert('请将信息填写完整！')
        return
      }
      if (!/^1(3|4|5|7|8)\d{9}$/.test(this.inputPhone)) {
        alert('手机号码有误，请重填')
        return
      }
      this.$store.state.city = this.inputCity
      this.$router.push('/index')
    },
    checkedNan () {
      this.who = '先生'
      this.checked1 = true
    },
    checkedNan2 () {
      this.who = '女士'
      this.checked1 = false
    }
  }
}
</script>

<style lang='stylus' scoped>
.search {
  display: flex;
  flex-wrap: wrap;
  width: 40%;
  padding: 0 0.1rem;
  margin-top: 1rem;
  margin-left: 7rem;

  .welcome {
    width: 100%;
    height: 30px;
    font-size: 26px;
  }

  .address {
    display: flex;
    width: 100%;
    margin-top: 0.7rem;

    .add-test {
      font-size: 14px;
      line-height: 0.5rem;
    }
  }

  .search-input {
    box-sizing: border-box;
    width: 4rem;
    height: 0.4rem;
    line-height: 0.62rem;
    padding: 0 0.1rem;
    margin-left: 0.6rem;
    border: 1px solid #9fa4a4;
  }

  .man {
    display: flex;
    width: 100%;
    margin-top: 0.3rem;

    .man-test {
      font-size: 14px;
      line-height: 0.5rem;
    }
  }

  .man-input {
    box-sizing: border-box;
    width: 4rem;
    height: 0.4rem;
    line-height: 0.62rem;
    margin-left: 0.87rem;
    padding: 0 0.1rem;
    border: 1px solid #9fa4a4;
  }

  .sex {
    margin-left: 0.6rem;
    line-height: 0.45rem;
  }

  .num {
    display: flex;
    width: 100%;
    margin-top: 0.3rem;

    .num-test {
      font-size: 14px;
      line-height: 0.5rem;
    }
  }

  .num-input {
    box-sizing: border-box;
    width: 4rem;
    height: 0.4rem;
    line-height: 0.62rem;
    margin-left: 0.6rem;
    padding: 0 0.1rem;
    border: 1px solid #9fa4a4;
  }

  .save {
    width: 1.8rem;
    height: 0.45rem;
    background: rgb(228, 57, 60);
    color: white;
    margin-left: 0.6rem;
  }

  .tips {
    width: 6rem;
    height: 3rem;
    margin-top: 0.4rem;
    margin-left: 1.78rem;

    .tips-test {
      font-size: 12px;
      color: #aaa;
    }
  }
}
</style>
